//
//  CXHAppDelegate.m
//  CXHAdSDK-ToBid
//
//  Created by 二跳 on 04/03/2025.
//  Copyright (c) 2025 二跳. All rights reserved.
//

#import "CXHAppDelegate.h"
#import <WindMillSDK/WindMillSDK.h>

@interface CXHAppDelegate ()<WindMillSplashAdDelegate>

@property (nonatomic, strong) WindMillSplashAd *splashAd;

@end

@implementation CXHAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    
    [WindMillAds setDebugEnable:YES];
    //初始化SDK
    [WindMillAds setupSDKWithAppId:@"58175"];
    
//    [self loadSplashAd];
    return YES;
}

- (void)loadSplashAd{
    WindMillAdRequest *request = [WindMillAdRequest request];
    request.placementId = @"6293292754548425";
//    request.userId = @"";
    self.splashAd = [[WindMillSplashAd alloc] initWithRequest:request extra:nil];
    self.splashAd.delegate = self;
    self.splashAd.rootViewController = self.window.rootViewController;
    [self.splashAd loadAd];
}

#pragma mark - WindMillSplashAdDelegate

/// 广告加载成功回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
- (void)onSplashAdDidLoad:(WindMillSplashAd *)splashAd{
    NSLog(@"%@ -- %@", NSStringFromSelector(_cmd), splashAd.placementId);
    [self.splashAd showAdInWindow:self.window withBottomView:nil];
}

/// 广告加载失败回调
/// - Parameters:
///   - splashAd: WindMillSplashAd 实例对象
///   - error: 具体错误信息
-(void)onSplashAdLoadFail:(WindMillSplashAd *)splashAd error:(NSError *_Nullable)error{
    
    NSLog(@"%@ -- %@", NSStringFromSelector(_cmd), splashAd.placementId);
}

/// 广告即将曝光回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
-(void)onSplashAdWillPresentScreen:(WindMillSplashAd *)splashAd{
    
    NSLog(@"%@ -- %@", NSStringFromSelector(_cmd), splashAd.placementId);
}

/// 广告曝光回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
-(void)onSplashAdSuccessPresentScreen:(WindMillSplashAd *)splashAd{
    
    NSLog(@"%@ -- %@", NSStringFromSelector(_cmd), splashAd.placementId);
}

/// 广告展示失败回调
/// - Parameters:
///   - splashAd: WindMillSplashAd 实例对象
///   - error: 具体错误信息
-(void)onSplashAdFailToPresent:(WindMillSplashAd *)splashAd withError:(NSError *_Nullable)error{
    
    NSLog(@"%@ -- %@", NSStringFromSelector(_cmd), splashAd.placementId);
}

/// 广告点击回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
- (void)onSplashAdClicked:(WindMillSplashAd *)splashAd{
    
    NSLog(@"%@ -- %@", NSStringFromSelector(_cmd), splashAd.placementId);
}

/// 广告跳过回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
- (void)onSplashAdSkiped:(WindMillSplashAd *)splashAd{
    
    NSLog(@"%@ -- %@", NSStringFromSelector(_cmd), splashAd.placementId);
}

/// 广告即将关闭回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
- (void)onSplashAdWillClosed:(WindMillSplashAd *)splashAd{
    
    NSLog(@"%@ -- %@", NSStringFromSelector(_cmd), splashAd.placementId);
}

/// 广告关闭回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
- (void)onSplashAdClosed:(WindMillSplashAd *)splashAd{
    
    NSLog(@"%@ -- %@", NSStringFromSelector(_cmd), splashAd.placementId);
}

/// This method is called when splash viewControllr is closed.
/// @Note :  当加载聚合维度广告时，支持该回调的adn有：CSJ
- (void)onSplashAdViewControllerDidClose:(WindMillSplashAd *)splashAd{
    
}

/// 广告小窗口点击回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
- (void)onSplashZoomOutViewAdDidClick:(WindMillSplashAd *)splashAd{
    
}


/// 广告小窗口关闭回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
- (void)onSplashZoomOutViewAdDidClose:(WindMillSplashAd *)splashAd{
    
}

/** 目前仅支持gromore csj gdt
 *  广告即将展示广告详情页回调
 */
- (void)onSplashAdWillPresentFullScreenModal:(WindMillSplashAd *)splashAd{
    
}

/// 竞价广告源开始竞价回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
///   - splashAd: 开屏信息
///   - adInfo: 广告的相关信息
- (void)splashAd:(WindMillSplashAd *)splashAd didStartBidADSource:(WindMillAdInfo *)adInfo{
    
}

/// 竞价广告源竞价成功回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
///   - splashAd: 开屏信息
///   - adInfo: 广告的相关信息
- (void)splashAd:(WindMillSplashAd *)splashAd didFinishBidADSource:(WindMillAdInfo *)adInfo{
    
}

/// 竞价广告源竞价失败回调，以及失败原因
/// - Parameters:
///   - splashAd: WindMillSplashAd 实例对象
///   - adInfo: 具体错误信息
- (void)splashAd:(WindMillSplashAd *)splashAd didFailBidADSource:(WindMillAdInfo *)adInfo error:(NSError *_Nullable)error{
    
}

/// 广告源开始加载回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
///   - splashAd: 开屏信息
///   - adInfo: 广告的相关信息
- (void)splashAd:(WindMillSplashAd *)splashAd didStartLoadingADSource:(WindMillAdInfo *)adInfo{
    
}

/// 广告源广告填充回调
/// - Parameter splashAd: WindMillSplashAd 实例对象
///   - splashAd: 开屏信息
///   - adInfo: 广告的相关信息
- (void)splashAd:(WindMillSplashAd *)splashAd didFinishLoadingADSource:(WindMillAdInfo *)adInfo{
    
}

/// 广告源加载失败回调，以及失败原因
/// - Parameters:
///   - splashAd: WindMillSplashAd 实例对象
///   - error: 具体错误信息
- (void)splashAd:(WindMillSplashAd *)splashAd didFailToLoadADSource:(WindMillAdInfo *)adInfo error:(NSError *_Nullable)error{
    
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
